﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Domain.MainModule.Entities;
using Infraestructure.Data.MainModule.UnitOfWork;
using Infraestructure.CrossCutting.Logging;
using Domain.MainModule.VirtualAccounts;
using Infraestructure.Data.MainModule.Repositories;

namespace Infraestructure.Data.MainModule.Tests.RepositoriesTests
{
    [TestClass()]
    public class VirtualAccountRepositoryTest : RepositoryTestsBase<VirtualAccount>
    {
       
       public override System.Linq.Expressions.Expression<Func<VirtualAccount, bool>> FilterExpression
        {
            get { return a => a.VirtualAccountId == TestConstants.Instance.VIRTUAL_ACCOUNT_ID; }
        }

        public override System.Linq.Expressions.Expression<Func<VirtualAccount, Guid>> OrderByExpression
        {
            get { return a => a.VirtualAccountId; }
        }
		
		[TestMethod()]
        [ExpectedException(typeof(ArgumentNullException))]
        public void FindVirtualAccount_Invoke_NullSpecThrowNewArgumentNullException_Test()
        {
            //Arrange 
            IMainModuleUnitOfWork context = GetUnitOfWork();
            ITraceManager traceManager = this.GetTraceManager();
            IVirtualAccountRepository repository = new VirtualAccountRepository(context,traceManager);

            //Act
            repository.FindVirtualAccount(null);
        }

        #region VirtualAccountVirtualAccountIdSpecification

        [TestMethod()]
        public void FindVirtualAccount_Invoke_InvalidVirtualAccountIdReturnNullObject_Test()
        {
            //Arrange 
            IMainModuleUnitOfWork context = GetUnitOfWork();
            ITraceManager traceManager = this.GetTraceManager();
            IVirtualAccountRepository repository = new VirtualAccountRepository(context, traceManager);

			Guid invalidId = new Guid("11111111-1111-1111-1111-111111111111");
            VirtualAccountVirtualAccountIdSpecification spec = new VirtualAccountVirtualAccountIdSpecification(invalidId);

            //Act
            VirtualAccount virtualAccount = repository.FindVirtualAccount(spec);

            //Assert
            Assert.IsNull(virtualAccount);
        }
		
        [TestMethod()]
        public void FindVirtualAccountByVirtualAccountId_Invoke_Test()
        {
            //Arrange 
            IMainModuleUnitOfWork context = GetUnitOfWork();
            ITraceManager traceManager = this.GetTraceManager();
            IVirtualAccountRepository repository = new VirtualAccountRepository(context, traceManager);

            VirtualAccountVirtualAccountIdSpecification spec = new VirtualAccountVirtualAccountIdSpecification(TestConstants.Instance.VIRTUAL_ACCOUNT_ID);

            //Act
            VirtualAccount virtualAccount = repository.FindVirtualAccount(spec);

            //Assert
            Assert.IsNotNull(virtualAccount);
        }

        #endregion

        #region VirtualAccountUserIdSpecification

        [TestMethod()]
        public void FindVirtualAccount_Invoke_InvalidVirtualAccountUserIdReturnNullObject_Test()
        {
            //Arrange 
            IMainModuleUnitOfWork context = GetUnitOfWork();
            ITraceManager traceManager = this.GetTraceManager();
            IVirtualAccountRepository repository = new VirtualAccountRepository(context, traceManager);

            Guid invalidId = new Guid("11111111-1111-1111-1111-111111111111");
            VirtualAccountUserIdSpecification spec = new VirtualAccountUserIdSpecification(invalidId);

            //Act
            VirtualAccount virtualAccount = repository.FindVirtualAccount(spec);

            //Assert
            Assert.IsNull(virtualAccount);
        }

        [TestMethod()]
        public void FindVirtualAccountByVirtualAccountUserId_Invoke_Test()
        {
            //Arrange 
            IMainModuleUnitOfWork context = GetUnitOfWork();
            ITraceManager traceManager = this.GetTraceManager();
            IVirtualAccountRepository repository = new VirtualAccountRepository(context, traceManager);

            VirtualAccountUserIdSpecification spec = new VirtualAccountUserIdSpecification(TestConstants.Instance.USER_ID);

            //Act
            IEnumerable<VirtualAccount> result = repository.FindVirtualAccounts(spec);

            //Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Count() > 0);
        }

        #endregion
    }
}
